package com.sl.au.service.impl;

import com.sl.au.entity.AfterSaleReturnVisit;
import com.sl.au.repository.AfterSaleReturnVisitRepository;
import com.sl.au.service.AfterSaleReturnVisitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("AfterSaleReturnVisitService")
@Transactional
public class AfterSaleReturnVisitServiceImpl extends BaseServiceImpl implements AfterSaleReturnVisitService {

    @Autowired
    AfterSaleReturnVisitRepository afterSaleReturnVisitRepository;
    @Override
    public List<AfterSaleReturnVisit> getPage(int start, int length, String key, String orderName, String dir) {
        Page<AfterSaleReturnVisit> pages=null;
        Pageable pageable=new PageRequest(start/length,length,Sort.Direction.DESC,"createTime");
        pages=afterSaleReturnVisitRepository.findAll(pageable);
        return pages.getContent();
    }
    @Override
    public List<AfterSaleReturnVisit> getAfterSaleReturnVisit(int start, int length,String key,String orderName ,String dir){
        Page<AfterSaleReturnVisit> pages = null;
        Pageable pageable=new PageRequest(start/length,length, Sort.Direction.DESC,"id");
        pages = afterSaleReturnVisitRepository.getAfterSaleReturnVisitTitle(key, pageable);

        return pages.getContent();
    }
    @Override
    public List<AfterSaleReturnVisit> getIndex(int start, int length,String key,String orderName ,String dir){
        Page<AfterSaleReturnVisit> pages = null;
        Pageable pageable=new PageRequest(start/length,length, Sort.Direction.DESC,"id");
        pages = afterSaleReturnVisitRepository.getAfterSaleReturnVisitTitle(key, pageable);
        return pages.getContent();
    }
    @Override
    public AfterSaleReturnVisitRepository getRepository() {
        return afterSaleReturnVisitRepository;
    }

}